package view.ui
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	public class ProgressView extends Sprite
	{
		[Embed(source="asset/loading_bg.png")]
		protected var _bg_jpg:Class;
		protected var bg_jpg:Bitmap;
		
		[Embed(source="asset/gou.png")]
		protected var _gou_jpg:Class;
		protected var gou_jpg:Bitmap;
		
		protected var progress_bar:ProgressBar;
		protected var _mask:Sprite;
		protected var per:Number;
		
		protected var info:InfoTextField;
		protected var percent:PercentTextField;
		public function ProgressView()
		{
			super();
			init();
		}
		
		protected function init():void
		{
			bg_jpg=new _bg_jpg() as Bitmap;
			bg_jpg.smoothing=true;
			this.addChild(bg_jpg);
			
			progress_bar=new ProgressBar();
			progress_bar.black();
			this.addChild(progress_bar);
			progress_bar.x=8;
			progress_bar.y=25;
			_mask=new Sprite();
			_mask.graphics.beginFill(0,0);
			_mask.graphics.drawRect(0,0,progress_bar.width,progress_bar.height);
			_mask.graphics.endFill();
			this.addChild(_mask);
			progress_bar.mask=_mask;
			_mask.x=progress_bar.x;
			_mask.y=progress_bar.y;
			per=_mask.width/100;
			
			info=new InfoTextField();
			info.x=10;
			info.y=5;
			this.addChild(info);
			percent=new PercentTextField();
			percent.x=280;
			percent.y=5;
			
			this.addChild(percent);
			
			gou_jpg=new _gou_jpg() as Bitmap;
			gou_jpg.smoothing=true;
			this.addChild(gou_jpg);
			gou_jpg.x=300;
			gou_jpg.y=5;
			gou_jpg.visible=false;
			progress(0);
		}
		
		public function set text(value:String):void
		{
			info.text=value;
		}
		
		public function progress(value:Number):void
		{
			_mask.width=value*per;
			percent.text=Math.floor(value).toString()+"%";
			if(value==100)
			{
				complete();
				progress_bar.green();
			}
		}
		
		public function red():void
		{
			progress_bar.red();
			gou_jpg.visible=false;
			percent.text="!";
		}
		
		public function complete():void
		{
			gou_jpg.visible=true;
			percent.visible=false;
		}
	}
}